package com.cloud.wms.base;

import android.view.ViewGroup;

import androidx.annotation.IdRes;

import com.cloud.core.base.BasePresenter;
import com.cloud.core.multistate.NavIconType;
import com.cloud.core.multistate.ToolbarAdapter;
import com.cloud.wms.tools.BarAdapter;
import com.cloud.wms.ui.main.activity.BaseInfoActivity;
import com.dylanc.loadinghelper.LoadingHelper;
import com.dylanc.loadinghelper.ViewType;

/**
 * @Author:Chen
 * @Date: 2021-01-14 14:12
 * @Description:
 */
public abstract class BaseBarActivity<P extends BasePresenter> extends BaseActivity<P> {

    @Override
    public void setContentView(int layoutResID) {
        this.setContentView(layoutResID, android.R.id.content);
    }

    public void setContentView(int layoutResID, @IdRes int contentViewId) {
        this.setContentView(layoutResID, contentViewId, null);
    }

    public void setContentView(int layoutResID, @IdRes int contentViewId, LoadingHelper.ContentAdapter<?> contentAdapter) {
        super.setContentView(layoutResID);
        loadingHelper = new LoadingHelper(((ViewGroup) findViewById(contentViewId)).getChildAt(0), contentAdapter);
        loadingHelper.setOnReloadListener(this);
    }

    protected void initToolBar() {
        loadingHelper.register(ViewType.TITLE, new BarAdapter(barTitle(), NavIconType.BACK, false, v -> switchBaseInfo()));
        loadingHelper.setDecorHeader(ViewType.TITLE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        loadingHelper.getAdapter(ViewType.TITLE).notifyDataSetChanged();
    }

    protected abstract String barTitle();

    /**
     * 切换仓库
     */
    public void switchBaseInfo() {

    }

    /**
     * 切换会员
     */
    public void switchMember() {
        BaseInfoActivity.start(this, true);
    }
}
